package com.iknow.ui.model;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.activity.FriendActivity;
import com.iknow.activity.LoginActivity;
import com.iknow.activity.TagQingboActivity;
import com.iknow.data.QingBo;
import com.iknow.data.QingboType;
import com.iknow.data.SubscribeTag;
import com.iknow.db.IKnowDataBase;
import com.iknow.image.ImageCache;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;
import com.iknow.util.SystemUtil;
import com.iknow.xmpp.service.Friend;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class QingBoAdapter extends BaseAdapter
{
  private View.OnClickListener ProfileImageClickLitener;
  private final String TAG = "QingBoAdapter";
  private View.OnClickListener TagViewClickListener;
  private List<Bitmap> mCacheBitmapList;
  private Context mContext;
  private boolean mHeadImageClickAble = true;
  private LayoutInflater mLayoutInflater;
  private ProfileImageCacheManager mProfileImageCacheManager;
  private List<QingBo> mQingBoList;
  private boolean mScrolling;
  private boolean mShowTagView = false;
  private DateFormat mSimpleDateFormat;

  public QingBoAdapter(Context paramContext, LayoutInflater paramLayoutInflater)
  {
    this.mScrolling = false;
    this.mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    this.TagViewClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        SubscribeTag localSubscribeTag = new SubscribeTag(((TextView)paramView).getText().toString(), "1");
        Intent localIntent = new Intent(QingBoAdapter.access$1(this.this$0), TagQingboActivity.class);
        localIntent.putExtra("tag", localSubscribeTag);
        QingBoAdapter.access$1(this.this$0).startActivity(localIntent);
      }
    };
    this.ProfileImageClickLitener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (!(QingBoAdapter.access$2(this.this$0)));
        while (true)
        {
          return;
          if (IKnow.mIKnowDataBase.getUser() != null)
            break;
          Intent localIntent1 = new Intent(QingBoAdapter.access$1(this.this$0), LoginActivity.class);
          QingBoAdapter.access$1(this.this$0).startActivity(localIntent1);
        }
        QingBo localQingBo = (QingBo)paramView.getTag();
        String str = localQingBo.getAuthorID() + "@" + "imiknow.com";
        Friend localFriend = IKnow.mIKnowDataBase.getFriendInfo(str);
        Intent localIntent2 = new Intent(QingBoAdapter.access$1(this.this$0), FriendActivity.class);
        if (localFriend != null)
          localIntent2.putExtra("friend", localFriend);
        while (true)
        {
          while (true)
            QingBoAdapter.access$1(this.this$0).startActivity(localIntent2);
          localIntent2.putExtra("friend", new Friend(str, localQingBo.getAuthorName(), localQingBo.getAuthorAvatar()));
        }
      }
    };
    this.mContext = paramContext;
    this.mLayoutInflater = paramLayoutInflater;
    this.mQingBoList = new ArrayList();
    this.mProfileImageCacheManager = new ProfileImageCacheManager();
    this.mCacheBitmapList = new ArrayList();
  }

  private void fillDataToView(QingBo paramQingBo, View paramView)
  {
    QingBoViewHolder localQingBoViewHolder = (QingBoViewHolder)paramView.getTag();
    localQingBoViewHolder.ProfileImage.setOnClickListener(this.ProfileImageClickLitener);
    if (!(StringUtil.isEmpty(paramQingBo.getAuthorAvatar())))
    {
      Bitmap localBitmap2 = localQingBoViewHolder.ProfileImage.getDrawingCache();
      if ((localBitmap2 != null) && (localBitmap2 != ImageCache.mDefaultProfileBitmap))
      {
        if (!(localBitmap2.isRecycled()))
        {
          Loger.i("QingBoAdapter", "recycle--" + localBitmap2.toString());
          localBitmap2.recycle();
        }
        localQingBoViewHolder.ProfileImage.setDrawingCacheEnabled(false);
      }
    }
    try
    {
      if (!(this.mScrolling))
      {
        localQingBoViewHolder.ProfileImage.setDrawingCacheEnabled(true);
        IKnow.mProfileImageCacheManager.displayProfileBimap(localQingBoViewHolder.ProfileImage, IKnowApiV4.formatFileUrl(paramQingBo.getAuthorAvatar()));
        localQingBoViewHolder.ProfileImage.setTag(paramQingBo);
        localQingBoViewHolder.Author.setText(paramQingBo.getAuthorName());
        localQingBoViewHolder.Author.setTag(paramQingBo);
        localQingBoViewHolder.Author.setOnClickListener(this.ProfileImageClickLitener);
        if (this.mShowTagView)
        {
          localQingBoViewHolder.TagView.setVisibility(0);
          localQingBoViewHolder.TagView.setText(paramQingBo.getTags());
          localQingBoViewHolder.TagImage.setVisibility(0);
        }
        localQingBoViewHolder.ReadCount.setText(paramQingBo.getHot());
        localQingBoViewHolder.FavCount.setText(paramQingBo.getFavoriteCount());
        localQingBoViewHolder.CommentCount.setText(paramQingBo.getCommentCount());
        localQingBoViewHolder.Date.setText(SystemUtil.compareDate(this.mSimpleDateFormat.format(paramQingBo.getCreateTime())));
        localQingBoViewHolder.Title.setText(paramQingBo.getTitle());
        if (StringUtil.isEmpty(paramQingBo.getThumbnailUrl()))
          break label483;
        localQingBoViewHolder.CoverImageBg.setVisibility(0);
        if (localQingBoViewHolder.CoverImage != null)
        {
          Bitmap localBitmap1 = localQingBoViewHolder.CoverImage.getDrawingCache();
          if ((localBitmap1 != null) && (localBitmap1 != ImageCache.mDefaultBitmap))
          {
            if (!(localBitmap1.isRecycled()))
            {
              Loger.i("QingBoAdapter", "recycle--" + localBitmap1.toString());
              localBitmap1.recycle();
            }
            localQingBoViewHolder.CoverImage.setDrawingCacheEnabled(false);
          }
        }
        if (this.mScrolling)
          break label470;
        localQingBoViewHolder.CoverImage.setDrawingCacheEnabled(true);
        IKnow.mProfileImageCacheManager.displayContentBimap(localQingBoViewHolder.CoverImage, IKnowApiV4.formatFileUrl(paramQingBo.getThumbnailUrl()));
        if (!(StringUtil.isEmpty(paramQingBo.getSubject())))
          break label495;
        localQingBoViewHolder.Subject.setVisibility(8);
        if (paramQingBo.getType() != QingboType.audio)
          break label517;
        localQingBoViewHolder.media.setVisibility(0);
        return;
      }
      label517: label470: label483: label495: localQingBoViewHolder.ProfileImage.setImageResource(2130837551);
    }
    catch (RuntimeException localRuntimeException)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                  Loger.e("QingBoAdapter", localRuntimeException.getMessage());
                localQingBoViewHolder.ProfileImage.setImageResource(2130837551);
              }
              localQingBoViewHolder.CoverImage.setImageBitmap(ImageCache.mDefaultBitmap);
            }
            localQingBoViewHolder.CoverImageBg.setVisibility(8);
          }
          localQingBoViewHolder.Subject.setText(paramQingBo.getSubject());
          localQingBoViewHolder.Subject.setVisibility(0);
        }
        localQingBoViewHolder.media.setVisibility(8);
      }
    }
  }

  private View newView(QingBo paramQingBo)
  {
    View localView = this.mLayoutInflater.inflate(2130903131, null);
    QingBoViewHolder localQingBoViewHolder = new QingBoViewHolder(this, null);
    localQingBoViewHolder.ProfileImage = ((ImageView)localView.findViewById(2131296543));
    localQingBoViewHolder.Author = ((TextView)localView.findViewById(2131296544));
    localQingBoViewHolder.FavCount = ((TextView)localView.findViewById(2131296546));
    localQingBoViewHolder.CommentCount = ((TextView)localView.findViewById(2131296547));
    localQingBoViewHolder.Date = ((TextView)localView.findViewById(2131296288));
    localQingBoViewHolder.ReadCount = ((TextView)localView.findViewById(2131296552));
    localQingBoViewHolder.Title = ((TextView)localView.findViewById(2131296490));
    localQingBoViewHolder.CoverImageBg = ((RelativeLayout)localView.findViewById(2131296549));
    localQingBoViewHolder.CoverImage = ((ImageView)localView.findViewById(2131296300));
    localQingBoViewHolder.Subject = ((TextView)localView.findViewById(2131296550));
    localQingBoViewHolder.media = ((ImageView)localView.findViewById(2131296553));
    localQingBoViewHolder.TagView = ((TextView)localView.findViewById(2131296555));
    localQingBoViewHolder.TagView.setOnClickListener(this.TagViewClickListener);
    localQingBoViewHolder.TagImage = ((ImageView)localView.findViewById(2131296554));
    localView.setTag(localQingBoViewHolder);
    return localView;
  }

  private void recycleCache(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= this.mCacheBitmapList.size()));
    while (true)
    {
      Bitmap localBitmap;
      do
      {
        return;
        localBitmap = (Bitmap)this.mCacheBitmapList.get(paramInt);
      }
      while ((localBitmap == null) || (localBitmap.isRecycled()));
      Loger.i("QingBoAdapter", "recycleCache " + localBitmap.toString());
      localBitmap.recycle();
      this.mCacheBitmapList.remove(paramInt);
    }
  }

  public void addQingBo(QingBo paramQingBo)
  {
    this.mQingBoList.add(paramQingBo);
  }

  public void addQingboAtFoot(List<QingBo> paramList)
  {
    this.mQingBoList.addAll(paramList);
  }

  public void addQingboAtHead(List<QingBo> paramList)
  {
    if (paramList != null)
      this.mQingBoList.addAll(0, paramList);
  }

  public void clearQingBo(int paramInt)
  {
    this.mQingBoList.remove(paramInt);
  }

  public void clearQingBoList()
  {
    releaseAllCacheBitmap();
    this.mQingBoList.clear();
  }

  public void clearQingboList(int paramInt1, int paramInt2)
  {
    if (paramInt1 < 0)
      return;
    if (paramInt2 > this.mQingBoList.size())
      paramInt2 = this.mQingBoList.size();
    Iterator localIterator = this.mQingBoList.iterator();
    while (true)
    {
      if ((!(localIterator.hasNext())) || (paramInt1 > paramInt2));
      localIterator.next();
      localIterator.remove();
      ++paramInt1;
    }
  }

  public int getCacheBimapSize()
  {
    return this.mProfileImageCacheManager.getImageManager().getCacheBitmapSize();
  }

  public int getCount()
  {
    return this.mQingBoList.size();
  }

  public QingBo getItem(int paramInt)
  {
    QingBo localQingBo;
    if ((paramInt < 0) || (paramInt > getCount()))
      localQingBo = null;
    while (true)
    {
      return localQingBo;
      localQingBo = (QingBo)this.mQingBoList.get(paramInt);
    }
  }

  public long getItemId(int paramInt)
  {
    return paramInt;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    View localView;
    QingBo localQingBo = getItem(paramInt);
    if (localQingBo == null)
      localView = null;
    while (true)
    {
      return localView;
      if (paramView == null)
        paramView = newView(localQingBo);
      fillDataToView(localQingBo, paramView);
      localView = paramView;
    }
  }

  public void realeaseBitmap(String paramString)
  {
    this.mProfileImageCacheManager.getImageManager().recycleBitmap(paramString);
  }

  public void releaseAllCacheBitmap()
  {
  }

  public void scrollIdle(AbsListView paramAbsListView)
  {
    this.mScrolling = false;
    paramAbsListView.invalidateViews();
  }

  public void setHeadImageClickAble(boolean paramBoolean)
  {
    this.mHeadImageClickAble = paramBoolean;
  }

  public void setQingBoList(List<QingBo> paramList)
  {
    this.mQingBoList = paramList;
  }

  public void setScrolling(boolean paramBoolean)
  {
    this.mScrolling = paramBoolean;
  }

  public void setShowTagView(boolean paramBoolean)
  {
    this.mShowTagView = paramBoolean;
  }

  public void updateQingboList(List<QingBo> paramList)
  {
  }

  private class QingBoViewHolder
  {
    public TextView Author;
    public TextView CommentCount;
    public ImageView CoverImage;
    public RelativeLayout CoverImageBg;
    public TextView Date;
    public TextView FavCount;
    public ImageView ProfileImage;
    public TextView ReadCount;
    public TextView Subject;
    public ImageView TagImage;
    public TextView TagView;
    public TextView Title;
    public ImageView media;
  }
}